package es.juanc.threads;

public class ThreadsTest {

	public static void main( String[] args ) {

		Runnable runnable = new Runnable() {
			public void run() {
				System.out.println( "soy " + Thread.currentThread().getId() + " - " + Thread.currentThread().getName() );
//				for ( Thread th : Thread.getAllStackTraces().keySet() ) {
//					System.out.println( Thread.currentThread().getId() + " hilo: " + th.getName() );
//				}
//				System.out.println( "----------------------------------------" );

			}
		};

		ThreadGroup tg = new ThreadGroup( "ESTE" );

		new Thread(tg, runnable, "El primer").start();

		new Thread(tg, runnable, "El segun").start();

		new Thread(tg, runnable).start();

		System.out.println( "Hilos activos: " + Thread.activeCount() );

		for ( Thread th : Thread.getAllStackTraces().keySet() ) {
			System.out.println( Thread.currentThread().getId() + " hilo: " + th.getName() );
		}

		System.out.println( "----------------------------------------" );

		Thread[] ths = new Thread[ tg.activeCount() ];
		tg.enumerate(ths);
		for ( Thread th : ths ) {
			System.out.println( Thread.currentThread().getId() + " hilo: " + th.getName() );
		}

		System.out.println( "----------------------------------------" );

		System.out.println( "Fin: " + Thread.currentThread().getId() + " - " + Thread.currentThread().getName() );
	}
}